package com.example.fresh;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.fragment.app.Fragment;

import com.example.Home.BackActivity;
import com.example.Home.EditActivity;
import com.example.Home.HelpActivity;

public class HomeFragment extends Fragment{

    public  View view;
    public LinearLayout editLayout;
    public LinearLayout rebackLayout;
    public LinearLayout helpLayout;
    public LinearLayout shareLayout;
    public HomeFragment(){

    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        view =  inflater.inflate(R.layout.fragment_home, container, false);
        editLayout = (LinearLayout) view.findViewById(R.id.layout1);
        rebackLayout = (LinearLayout) view.findViewById(R.id.layout2);
        helpLayout = (LinearLayout) view.findViewById(R.id.layout3);
        shareLayout = (LinearLayout) view.findViewById(R.id.layout4);
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);
        editLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), EditActivity.class);
                startActivity(intent);
            }
        });
        rebackLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), BackActivity.class);
                startActivity(intent);
            }
        });
        helpLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), HelpActivity.class);
                startActivity(intent);
            }
        });
        shareLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                // 比如发送文本形式的数据内容
//                // 指定发送的内容
                sendIntent.putExtra(Intent.EXTRA_TEXT, "Welcome To Keep Fresh");
                // 指定发送内容的类型
                sendIntent.setType("text/plain");
//                 比如发送二进制文件数据流内容（比如图片、视频、音频文件等等）
                // 指定发送的内容 (EXTRA_STREAM 对于文件 Uri )
                sendIntent.putExtra(Intent.EXTRA_STREAM, R.drawable.share);
                // 指定发送内容的类型 (MIME type)
                sendIntent.setType("image/png");
                startActivity(Intent.createChooser(sendIntent, "Share to..."));
            }
        });
    }
}
